<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Db_test extends CI_Controller {

	function __construct()
	{
		parent::__construct();

		$this->load->helper('form');
		$this->load->helper('url');
		$this->load->database();
	}

	function index()
	{
		
		
	}
	
	function backup()
	{
		
		// 加载数据库工具类
$this->load->dbutil();

// 备份整个数据库并将其赋值给一个变量
$backup =& $this->dbutil->backup(); 

// 加载文件辅助函数并将文件写入你的服务器
$this->load->helper('file');
write_file('/path/to/mybackup.gz', $backup); 

// 加载下载辅助函数并将文件发送到你的桌面
$this->load->helper('download');
force_download('mybackup.gz', $backup);
	}
	
	function count_test()
	{
		echo $this->db->count_all('users');
	}
	
	function backup2()
	{
		
		$this->load->dbutil();
		$prefs = array(
                'tables'      => array('users', 'main'),  // Array of tables to backup.
                'ignore'      => array(),           // List of tables to omit from the backup
                'format'      => 'txt',             // gzip，zip，txt
                'filename'    => 'mybackup.sql',    // File name - NEEDED ONLY WITH ZIP FILES
                'add_drop'    => TRUE,              // Whether to add DROP TABLE statements to backup file
                'add_insert'  => TRUE,              // Whether to add INSERT data to backup file
                'newline'     => "\n"               // Newline character used in backup file
              );

$backup = $this->dbutil->backup($prefs);
// 加载文件辅助函数并将文件写入你的服务器
$this->load->helper('file');
write_file('/path/to/mybackup.gz', $backup); 

// 加载下载辅助函数并将文件发送到你的桌面
$this->load->helper('download');
force_download('mybackup.gz', $backup);

		
	}
	
	function read()
	{
		$query = $this->db->get( 'users' );

        if( $query->num_rows() > 0 ) {
            $return_array = $query->result();
        } else {
            $return_array = array();
        }
		echo json_encode( $return_array );
	}


	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */